#include "stdafx.h"
#include "IExampleEvts.h"
#include "MyClassFactory.h"

BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
    switch (dwReason)
    {
    case DLL_PROCESS_ATTACH:
        ExampleEvtsTypeInfo = NULL;
        OutstandingObjects = 0;
        LockCount = 0;
        DisableThreadLibraryCalls(hModule);
        break;

    case DLL_PROCESS_DETACH:
        if (ExampleEvtsTypeInfo) ExampleEvtsTypeInfo->Release();
        break;
    }
    return TRUE;
}

HRESULT STDAPICALLTYPE DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
    if (!IsEqualCLSID(rclsid, CLSID_IExampleEvts))
    {
        *ppv = 0;
        return CLASS_E_CLASSNOTAVAILABLE;
    }
    return ClassFactory.QueryInterface(riid, ppv);
}

HRESULT STDAPICALLTYPE DllCanUnloadNow()
{
    return OutstandingObjects || LockCount ? S_FALSE : S_OK;
}
